using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;

namespace OurWedding1.Models
{ 
    public class HomePageParagraphRepository : IHomePageParagraphRepository
    {
        readonly WeddingEntities context = new WeddingEntities();

        public IQueryable<HomePageParagraph> All
        {
            get { return context.HomePageParagraphs; }
        }

        public IQueryable<HomePageParagraph> AllIncluding(params Expression<Func<HomePageParagraph, object>>[] includeProperties)
        {
            IQueryable<HomePageParagraph> query = context.HomePageParagraphs;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public HomePageParagraph Find(int id)
        {
            return context.HomePageParagraphs.Find(id);
        }

        public void InsertOrUpdate(HomePageParagraph homepageparagraph)
        {
            if (homepageparagraph.HomePageParagraphId == default(int)) {
                // New entity
                context.HomePageParagraphs.Add(homepageparagraph);
            } else {
                // Existing entity
                context.Entry(homepageparagraph).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var homepageparagraph = context.HomePageParagraphs.Find(id);
            context.HomePageParagraphs.Remove(homepageparagraph);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IHomePageParagraphRepository : IDisposable
    {
        IQueryable<HomePageParagraph> All { get; }
        IQueryable<HomePageParagraph> AllIncluding(params Expression<Func<HomePageParagraph, object>>[] includeProperties);
        HomePageParagraph Find(int id);
        void InsertOrUpdate(HomePageParagraph homepageparagraph);
        void Delete(int id);
        void Save();
    }
}